package com.zhuoxin.dao.admin;

import org.apache.commons.lang.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;

import com.zhuoxin.bean.model.Ask;
import com.zhuoxin.bean.model.AskSO;
import com.zhuoxin.dao.BaseDAOImpl;

public class AskDAOImpl extends BaseDAOImpl<Ask, AskSO> implements AskDAO {

	@Override
	public String getHqlWhere(AskSO so) {
		return null;
	}

	@Override
	public void setCriteriaParams(Criteria criteria, AskSO so) {
		if(StringUtils.isNotEmpty(so.getTitle())){
			criteria.add(Restrictions.ilike("title", "%"+StringUtils.trim(so.getTitle())+"%"));
		}
		
		if(StringUtils.isNotEmpty(so.getName())){
			criteria.add(Restrictions.ilike("name", "%"+StringUtils.trim(so.getName())+"%"));
		}
		
		if(StringUtils.isNotEmpty(so.getRemarker())){
			criteria.add(Restrictions.ilike("remarker", "%"+StringUtils.trim(so.getRemarker())+"%"));
		}
		
	}

	@Override
	public void setQueryParams(Query query, AskSO so) {
		
	}

	@Override
	public void switchVO2PO(Ask po, AskSO so) {
		if(StringUtils.isNotEmpty(so.getTitle())){
			po.setTitle(StringUtils.trim(so.getTitle()));
		}
		
		if(StringUtils.isNotEmpty(so.getTtime())){
			po.setTtime(StringUtils.trim(so.getTtime()));
		}
		
		if(StringUtils.isNotEmpty(so.getContent())){
			po.setContent(StringUtils.trim(so.getContent()));
		}
		
		if(StringUtils.isNotEmpty(so.getName())){
			po.setName(StringUtils.trim(so.getName()));
		}
		
		if(StringUtils.isNotEmpty(so.getPhone())){
			po.setPhone(StringUtils.trim(so.getPhone()));
		}
		
		if(StringUtils.isNotEmpty(so.getCompany())){
			po.setCompany(StringUtils.trim(so.getCompany()));
		}
		
		if(StringUtils.isNotEmpty(so.getAddress())){
			po.setAddress(StringUtils.trim(so.getAddress()));
		}
		
		if(StringUtils.isNotEmpty(so.getQq())){
			po.setQq(StringUtils.trim(so.getQq()));
		}
		
		if(StringUtils.isNotEmpty(so.getEmail())){
			po.setEmail(StringUtils.trim(so.getEmail()));
		}
		
		if(StringUtils.isNotEmpty(so.getRemarker())){
			po.setRemarker(StringUtils.trim(so.getRemarker()));
		}
		
		if(StringUtils.isNotEmpty(so.getRemarkContent())){
			po.setRemarkContent(StringUtils.trim(so.getRemarkContent()));
		}
		
		if(StringUtils.isNotEmpty(so.getRemarkTime())){
			po.setRemarkTime(StringUtils.trim(so.getRemarkTime()));
		}
		
		if(so.getSex()!=null){
			po.setSex(so.getSex());
		}
		
	}


}
